﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;


namespace Hue {
	/// <summary>
	/// Interaction logic for ColorWheel.xaml
	/// </summary>
	public partial class ColorWheel : UserControl {

		public event EventHandler<EventArgs> ColorChanged;
		private void OnColorChanged(EventArgs e) {
			EventHandler<EventArgs> handler = ColorChanged;
			if (handler != null) {
				ColorChanged(this, e);
			}
		}


		public System.Drawing.Color SelectedColor {
			get {
				//System.Drawing.Color returnValue = System.Drawing.Color.FromArgb(colorCanvas.SelectedColor.A, colorCanvas.SelectedColor.R, colorCanvas.SelectedColor.G, colorCanvas.SelectedColor.B);
				return System.Drawing.Color.FromArgb(colorCanvas.SelectedColor.A, colorCanvas.SelectedColor.R, colorCanvas.SelectedColor.G, colorCanvas.SelectedColor.B);
			}
			set {
				colorCanvas.SelectedColor = Color.FromArgb(value.A, value.R, value.G, value.B);
			}
		}

		public string ToHEXColor() {
			StringBuilder returnValue = new StringBuilder();
			returnValue.AppendFormat("#{0:X}{1:X}{2:X}", this.SelectedColor.R, this.SelectedColor.G, this.SelectedColor.B);
			return returnValue.ToString(); //colorCanvas.HexadecimalString;
		}

		public ColorWheel() {
			InitializeComponent();
			colorCanvas.SelectedColorChanged += new RoutedPropertyChangedEventHandler<Color>(colorCanvas_SelectedColorChanged);
		}

		public void colorCanvas_SelectedColorChanged(object sender, RoutedPropertyChangedEventArgs<Color> e) {
			OnColorChanged(EventArgs.Empty);
		}


	}
}
